package com.example.springboot.mybatisplus.controller;

import com.example.springboot.mybatisplus.common.R;
import com.example.springboot.mybatisplus.dal.entity.Emp;
import com.example.springboot.mybatisplus.service.IEmpService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Lei Yu
 * @since 2024-05-17
 */
@RestController
@RequestMapping("/emp")
public class EmpController {

    private final IEmpService iEmpService;

    public EmpController(IEmpService iEmpService) {
        this.iEmpService = iEmpService;
    }

    /**
     * <a href="http://localhost:8085/emp/getById">...</a>
     */
    @GetMapping("getById")
    public R<Emp> getById() {
        Emp data = iEmpService.getById(7369);
        return R.ok(data);
    }

    /**
     * <a href="http://localhost:8085/emp/getEmpListByName?ename=SMITH">...</a>
     */
    @GetMapping("getEmpListByName")
    List<Emp> getEmpListByName(@RequestParam String ename) {
        return iEmpService.getEmpListByName(ename);
    }

}
